package com.gxa.core.recycling.schedule;

import org.apache.logging.log4j.core.config.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

/**
 * 设计定时器,定时删除图片
 */

@Component
public class DeleteImgSchedule {

    /*@Scheduled(initialDelay = 1000, fixedDelayString = "3500")
    public void executeScheduledTask3() {
        String city = "成都";
        city = URLEncoder.encode(city);
        String requestURL =
                "https://www.sojson.com/open/api/weather/json.shtml?city=" + city;
        //    String requestURL = "http://www.weather.com.cn/data/sk/101270101.html ";

        String resultStr = "";
        try {
            URL url = new URL(requestURL);
            URLConnection urlConnection = url.openConnection();
            InputStream inputStream = urlConnection.getInputStream(); //字节流, 读取应该使用字节数组
            resultStr = org.apache.commons.io.IOUtils.toString(inputStream, "utf-8");
        } catch (
    IOException e) {
            e.printStackTrace();
        }
        //Weather.resultStr = resultStr;
        System.out.println("executeScheduledTask3 定时任务，线程ID=" +
                Thread.currentThread().getId() + ",线程名=" + Thread.currentThread().getName() + " count="
        );
    }



    @Scheduled(fixedRate = 4000)
    public void deleteImg() {

        //File file=new File("/usr/images/temp");
        //必须使用递归删除其中的所有文件
        //file.delete();
        System.out.println("DeleteImgSchedule deleteImg");
   }*/

}
